local jiangchi = fk.CreateSkill {
  name = "mini_ex__jiangchi",
}

Fk:loadTranslationTable{
  ["mini_ex__jiangchi"] = "将驰",
  [":mini_ex__jiangchi"] = "出牌阶段开始时，你可以选择一项：<br>"..
  "1.摸三张牌，本阶段不能使用【杀】；<br>"..
  "2.摸一张牌，本阶段造成伤害后摸一张牌；<br>"..
  "3.本阶段使用【杀】无距离限制，且可以多使用一张【杀】。",

  ["mini_ex__jiangchi_draw3"] = "摸三张牌，本阶段不能使用【杀】",
  ["mini_ex__jiangchi_draw1"] = "摸一张牌，本阶段造成伤害后摸一张牌",
  ["mini_ex__jiangchi_slash"] = "本阶段使用【杀】无距离限制，且可以多使用一张【杀】",
  ["@@mini_ex__jiangchi_prohibit-phase"] = "将驰 禁止出杀",
  ["@@mini_ex__jiangchi_damage-phase"] = "将驰 摸牌",
  ["@@mini_ex__jiangchi_targetmod-phase"] = "将驰 多出杀",

  ["$mini_ex__jiangchi1"] = "掩敌不备，一鼓而擒。",
  ["$mini_ex__jiangchi2"] = "见可而进，知难而退。",
}

jiangchi:addEffect(fk.EventPhaseStart, {
  anim_type = "drawcard",
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(jiangchi.name) and player.phase == Player.Play
  end,
  on_cost = function(self, event, target, player, data)
    local room = player.room
    local choice = room:askToChoice(player, {
      choices = {
        "mini_ex__jiangchi_draw3",
        "mini_ex__jiangchi_draw1",
        "mini_ex__jiangchi_slash",
        "Cancel",
      },
      skill_name = jiangchi.name,
    })
    if choice ~= "Cancel" then
      event:setCostData(self, {choice = choice})
      return true
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local choice = event:getCostData(self).choice
    if choice == "mini_ex__jiangchi_draw3" then
      room:setPlayerMark(player, "@@mini_ex__jiangchi_prohibit-phase", 1)
      player:drawCards(3, jiangchi.name)
    elseif choice == "mini_ex__jiangchi_draw1" then
      room:setPlayerMark(player, "@@mini_ex__jiangchi_damage-phase", 1)
      player:drawCards(1, jiangchi.name)
    elseif choice == "mini_ex__jiangchi_slash" then
      room:setPlayerMark(player, "@@mini_ex__jiangchi_targetmod-phase", 1)
    end
  end,
})

jiangchi:addEffect(fk.Damage, {
  anim_type = "drawcard",
  is_delay_effect = true,
  can_trigger = function (self, event, target, player, data)
    return target == player and player:getMark("@@mini_ex__jiangchi_damage-phase") > 0
  end,
  on_use = function (self, event, target, player, data)
    player:drawCards(1, jiangchi.name)
  end,
})

jiangchi:addEffect("targetmod", {
  residue_func = function(self, player, skill, scope, card)
    if card and card.trueName == "slash" and player:getMark("@@mini_ex__jiangchi_targetmod-phase") > 0 and
      scope == Player.HistoryPhase then
      return 1
    end
  end,
  bypass_distances = function(self, player, skill, card, to)
    return card and card.trueName == "slash" and player:getMark("@@mini_ex__jiangchi_targetmod-phase") > 0
  end,
})

jiangchi:addEffect("prohibit", {
  prohibit_use = function(self, player, card)
    return player:getMark("@@mini_ex__jiangchi_prohibit-phase") > 0 and card and card.trueName == "slash"
  end,
})

return jiangchi
